package com.qfedu.knowledge.controller;

import com.qfedu.knowledge.entity.vo.ResultVO;
import com.qfedu.knowledge.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FileInfoController
 * @Author ykx
 * @Date 2024/5/3 16:02
 * @Version 1.0
 */
@RestController
@RequestMapping("/knowledge/file")
public class FileInfoController {

    @Autowired
    private IFileService fileService;

    @GetMapping("/list/{questionId}")
    public ResultVO getFileList(@PathVariable("questionId") Long questionId) {
        return ResultVO.success(fileService.getFileList(questionId));
    }

    @GetMapping("/homeImage")
    public ResultVO getHomeImage() {
        return ResultVO.success(fileService.getHomeImage());
    }


    @DeleteMapping("delete/{id}")
    public ResultVO deleteFile(@PathVariable("id") Long id) {
        return ResultVO.success(fileService.removeById(id));
    }

    @GetMapping("/download")
    public ResponseEntity<byte[]> download(String downloadUrl, String name) {
        return fileService.download(downloadUrl, name);
    }

}
